package com.example.com.filelist;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import java.io.File;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {
    private static FO listener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        listener = new FO("/sdcard");
//        listener.startWatching();
        aa();
    }

    long all;
    long count;

    private void listFile(File f) throws IOException {
        if (f.isDirectory()) {
            File[] files = f.listFiles();
            if (files != null && files.length > 0) {
                for (File ff : files) {
                    if (ff.getAbsolutePath().equals(ff.getCanonicalPath())) {
                        listFile(ff);
                    } else {
                        Log.i("time", "no");
                    }
                }
            }
        } else {
            count++;
            all += f.length();
        }
    }

    public void aa() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                long begin = System.currentTimeMillis();
                File file = new File("/");
                try {
                    listFile(file);
                } catch (IOException e) {
                    e.printStackTrace();
                }

                long end = System.currentTimeMillis();

                Log.i("time", end - begin + "");
                Log.i("time", count + "");
                Log.i("time", all / 1024 / 1024 + "");

            }
        }).start();
    }
}
